package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallStoreModel;
import com.mallcloud.mall.mall.service.MallStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-门店")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/store")
public class MallStoreController {
    private final MallStoreService storeService;

    @ApiOperation("分页")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_store_view')")
    public R page(Page page, MallStoreModel dto) {
        return R.ok(storeService.page(page, Wrappers.query(dto)));
    }

    @ApiOperation("列表")
    @GetMapping("/list")
    @PreAuthorize("@pms.hasPermission('mall_store_view')")
    public R list(MallStoreModel dto) {
        return R.ok(storeService.listStore(dto));
    }

    @ApiOperation("查询")
    @GetMapping("/getInfo")
    @PreAuthorize("@pms.hasPermission('mall_store_view')")
    public R getInfo(MallStoreModel dto) {
        return R.ok(storeService.getInfo(dto));
    }

    @ApiOperation("新增")
	@PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_store_add')")
    public R save(@RequestBody MallStoreModel dto) {
		return R.ok(storeService.saveStore(dto));
    }

    @ApiOperation("修改")
	@PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_store_edit')")
    public R updateById(@RequestBody MallStoreModel dto) {
        return R.ok(storeService.updateStore(dto));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{storeNo}")
    @PreAuthorize("@pms.hasPermission('mall_store_del')")
    public R removeById(@PathVariable String storeNo) {
        return R.ok(storeService.removeStore(storeNo));
    }

	@ApiOperation("导出")
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('mall_store_export')")
    public List<MallStoreModel> export(MallStoreModel dto) {
        return storeService.list(Wrappers.query(dto));
    }
}
